<template>
  <div class="app-container">
    <el-form label-width="100px" :model="form">
      <el-form-item label="提交人：" style="float: left">
        <el-input v-model="form.serchKeyword" clearable placeholder="请输入提交人"/>
      </el-form-item>
      <el-button style="float: left;margin-left: 15px" type="primary" @click="Query(true)">查询</el-button>
    </el-form>
    <div class="clearfix"></div>
    <el-table :data="list" border fit header-cell-class-name="tableheader">
      <el-table-column
          type="index"
          width="50">
      </el-table-column>
      <el-table-column align="center" label="问题类型">
        <template slot-scope="scope">
          {{ scope.row.bug_type }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="问题描述">
        <template slot-scope="scope">
          {{ scope.row.bug_des }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="状态">
        <template slot-scope="scope">
          {{ scope.row.submit_state_str }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="提交人">
        <template slot-scope="scope">
          {{ scope.row.uname }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="解决人">
        <template slot-scope="scope">
          {{ scope.row.end_uname }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="图片" width="500">
        <template slot-scope="scope">
          <img width="85" style="margin-right: 5px" v-for="item in scope.row.bug_pic" :src="item" alt=""
               @click="opendialog(item)">
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="warning" size="mini" plain @click="chastate(scope.row)">修改状态</el-button>
          <el-button type="danger" size="mini" plain @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
          style="text-align: center"
          layout="prev, pager, next"
          small
          :current-page="form.page"
          :page-size="form.pagesize"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
    </div>
    <el-dialog :close-on-click-modal="false" title="寄件状态" :visible.sync="statedialog" width="25%">
      <el-form ref="statedialogform" :model="statedialogform" :rules="statedialogrule"
               label-width="100px">
        <el-form-item label="问题状态：" prop="submit_state">
          <el-select clearable v-model="statedialogform.submit_state" placeholder="请选择问题状态">
            <el-option label="未处理" :value="0"></el-option>
            <el-option label="解决中" :value="1"></el-option>
            <el-option label="已完成" :value="2"></el-option>
            <el-option label="忽略" :value="10"></el-option>
            <el-option label="设计如此" :value="11"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="statedialog = false">取消</el-button>
        <el-button type="primary" @click="statedialogbtn">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :append-to-body="true" :visible.sync="dialog">
      <div style="text-align: center">
        <img style="max-width: 500px;max-height: 800px" :src="dialogImage" alt="">
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      list: [],
      total: 0,
      form: {
        serchKeyword: "",
        isPage: true,
        page: 1,
        pagesize: 20,
      },
      dialog: false,
      dialogImage: '',
      statedialog: false,
      statedialogform: {
        bug_submit_id: '',
        submit_state: '',
      },
      statedialogrule: {
        submit_state: [
          { required: true, message: '此项为必填项' }
        ],
      }
    }
  },
  created() {
    this.Query()
  },
  methods: {
    //获取全部用户
    Query(isquery) {
      if (isquery === true) {
        this.form.page = 1
      }
      this.$post(this.$api + '/bug_submit/getpagelist', this.form)
          .then((data) => {
                if (data.code === 0) {
                  this.list = data.rows;
                  this.total = data.total;
                  for (var i in data.rows) {
                    data.rows[i].bug_pic = JSON.parse(data.rows[i].bug_pics)
                  }
                } else {
                  this.$notify({
                    title: '失败',
                    message: data.msg,
                    type: 'error'
                  });
                }
              }
          )
    },
    chastate(item) {
      this.statedialog = true;
      this.statedialogform.bug_submit_id = item.bug_submit_id
      this.statedialogform.submit_state = item.submit_state
    },
    del(item) {
      this.$confirm('确定删除该条bug记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$get(this.$api + '/bug_submit/del', {
          'bug_submit_id': item.bug_submit_id
        })
            .then((data) => {
                  if (data.code === 0) {
                    this.$notify({
                      title: '成功',
                      message: data.msg,
                      type: 'success'
                    });
                    this.Query()
                  } else {
                    this.$notify({
                      title: '失败',
                      message: data.msg,
                      type: 'error'
                    });
                  }
                }
            )
      })
    },
    opendialog(item) {
      this.dialog = true;
      this.dialogImage = item
    },
    statedialogbtn() {
      this.$get(this.$api + '/bug_submit/change_state', this.statedialogform)
          .then((data) => {
                if (data.code === 0) {
                  this.$notify({
                    title: '成功',
                    message: data.msg,
                    type: 'success'
                  });
                  this.statedialog = false
                  this.Query()
                } else {
                  this.$notify({
                    title: '失败',
                    message: data.msg,
                    type: 'error'
                  });
                }
              }
          )
    },
    handleSizeChange(v) {
      this.form.pagesize = v;
      this.Query();
    },
    handleCurrentChange(v) {
      this.form.page = v;
      this.Query();
    },
  }
}
</script>

<style scoped>

</style>
